﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common.Command;

namespace ZLCMS.Web.Wap.Example
{
    /// <summary>
    /// InterfaceExample命令参数
    /// </summary>
    public class InterfaceExampleParameter : ListCommandParameter
    {
        public string Param1 { get; set; }

        public string Param2 { get; set; }
    }

    /// <summary>
    /// InterfaceExample命令调用输出
    /// </summary>
    public class InterfaceExampleResult : CommandResult
    {
    }

    /// <summary>
    /// InterfaceExample命令
    /// </summary>
    public class InterfaceExampleCommand : SessionCommand
    {
        public override CommandResult Execute(NHibernate.ISession session, CommandParameter parameter)
        {
            InterfaceExampleResult result = new InterfaceExampleResult();
            InterfaceExampleParameter param = parameter as InterfaceExampleParameter;
            if (param != null)
            {
                result.TotalCount = 45;

                //在这里添加命令内容
                //result.Result = "hello world";
                IList<int> list = new List<int>();
                for (int i = (param.PageIndex - 1) * param.PageSize; i < param.PageIndex * param.PageSize && i < result.TotalCount; i++)
                {
                    list.Add(i);
                }
                result.Result = list;
            }
            else
            {
                result.ErrorCode = "0001";
            }
            return result;
        }

        protected override void PrepareExecute()
        {
            //在这里添加执行命令前的操作
        }

        protected override void AfterExecute()
        {
            //在这里添加执行命令后的操作
        }
    }
}
